package com.czxy.test;

import com.czxy.config.SpringConfig;
import com.czxy.dao.CategoryDao;
import com.czxy.dao.ProductDao;
import com.czxy.dao.UserDao;
import com.czxy.service.ProductService;
import com.czxy.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SpringConfig.class})
public class Demo02 {


    @Resource(name = "ud")
    private UserDao userDao;

    @Resource(name = "us")
    private UserService userService;

    @Resource
    private ProductService service;

    @Resource(name = "productDaoImplA")
//    @Resource
    private ProductDao productDao;



    private String driver;

    // root
    @Value("root")
    private String username;
    // root
    @Value("root")
    private String password;

    @Value("张三")
    private void show(String name){
        System.out.println("自动注入 name = "+name);
    }

    @Value("嘿嘿嘿")
    private void show02(String name,@Value("哈哈哈哈") String address){
        System.out.println("show02 name="+name+" address="+address);
    }

    @Test
    public void m03(){
        System.out.println("username= "+username+" password="+password);
    }



    @Value("${jdbc.driver}")
    private String driverClass;
    @Value("${jdbc.url}")
    private String url;

    @Test
    public void m05(){
        System.out.println("driverClass="+driverClass+" url="+url);
    }






    @Resource
    private CategoryDao categoryDao;

    @Test
    public void m07(){
        categoryDao.findAll();
    }









    @Test
    public void test03(){
        productDao.findAll();

    }




























    @Test
    public void test02(){
        service.findAll();
    }


    @Test
    public void t01(){
        userDao.findAll();
        System.out.println("---");
        userService.findAll();
    }

}
